<style>
    /* .editorBox{
        height: 300px;
    }  */
    .layuimini-main {
        min-height: 800px;
    }
    .btn{
        margin-top: 50px;
        margin-bottom:50px;
    }
</style>

<div class="layuimini-container layui-anim layui-anim-upbit">
    <div class="layuimini-main">
        <fieldset class="layui-elem-field layui-field-title">
            <legend style="font-size:medium;">添加动态新闻</legend>
        </fieldset>
        <form class="layui-form" action="" style="text-align:center">
            <!-- <div class="layui-form-item"> -->
            <div class="layui-input-inline">    
                <label class="layui-form-label">标题<label style="color: red;"> *</label>:</label>
                <div class="layui-input-block">
                    <input type="text"  style="width:890px"  name="addDy_title" id="addDy_title" lay-verify="required"
                        lay-reqtext="标题不能为空" placeholder="请输入标题" class="layui-input" spellcheck="false">
                </div>
            </div>
            <br><br>
            <div class="layui-input-inline" >
                <div class="layui-input-inline">
                    <label class="layui-form-label">来源<label style="color: red;"> *</label>:</label>
                    <div class="layui-input-inline">
                        <input type="text"  style="width:400px" id="addDy_source"
                            lay-verify="required" lay-reqtext="来源不能为空" placeholder="请输入来源" class="layui-input"
                            spellcheck="false">
                    </div>
                </div>
                <div class="layui-input-inline">
                    <label class="layui-form-label">发布日期:</label>
                    <div class="layui-input-inline" style="width: 375px;">
                        <input type="text" name="addDy_sendTime" id="addDy_sendTime" autocomplete="off"
                            class="layui-input">
                    </div>
                </div>
            </div>


            <br><br>        
            <div class="layui-inline">
                <div class="editorBox" id="editorId" name="gdesc" style="width: 1000px;min-height:460px;"></div>
            </div>
                    
            <div class="layui-form-item btn">
                <div class="layui-input-block">
                    <button class="layui-btn" id="submit" lay-submit lay-filter="saveBtn"  
                    style="position:absolute;right:21%;bottom:15px;border:none;outline:none;width: 90px;height:32px;line-height:32px;
                    background-color: #FFB800;font-size: 14px;color: #ffffff;">保存</button>
                    <button class="layui-btn" onclick="closeAddDynamic();" type="button"
                    style="position:absolute;right:11%;bottom:15px;border:none;outline:none;width: 90px;height:32px;line-height:32px;
                    background-color: #cccccc;font-size: 14px;color: #ffffff;">关闭</button> 
                </div>
            </div>
        </form>
    </div>

</div>
<!-- 富文本 -->
<script type="text/javascript" charset="utf-8" src="/lib/UEditor/ueditor.config.js"></script>
<!-- <script type="text/javascript" charset="utf-8" src="/lib/UEditor/ueditor.all.min.js"></script> -->
<script type="text/javascript" charset="utf-8" src="/lib/UEditor/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="/lib/UEditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
    //实例化编辑器
    var ue = UE.getEditor('editorId', {
            autoHeightEnabled: true,
            autoFloatEnabled: true,
            enableAutoSave: false,
            allowDivTransToP: false,//阻止div标签自动转换为p标签
            toolbars: [[
                'fullscreen', 'source', '|', 'undo', 'redo', '|',
                'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
                'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
                'directionalityltr', 'directionalityrtl', 'indent', '|',
                'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
                'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|',
                'insertimage', 'emotion', 'attachment', 'insertframe', 'insertcode', 'pagebreak', 'template', 'background', '|',
                'horizontal', 'date', 'time', 'spechars', 'wordimage', '|',
                'inserttable', 'deletetable', 'insertparagraphbeforetable', 'insertrow', 'deleterow', 'insertcol', 'deletecol', 'mergecells', 'mergeright', 'mergedown', 'splittocells', 'splittorows', 'splittocols', 'charts', '|',
                'preview',  'drafts', 'help'
            ]]
        });

    ue.ready(function () {
            //富文本跨域解决
            if(typeof(UE_Config_Json_LKJHGFDSA)!="undefined"){
                UE.utils.extend(ue.options, UE_Config_Json_LKJHGFDSA);
            }
        });
</script>
<script>
    //form表单
    layui.form.render();

    //开始日期
    var today = new Date();
    var start = layui.laydate.render({
        elem: '#addDy_sendTime',
        calendar: true,
        trigger: 'click',
        max: $("#addDy_sendTime").val(),
        istime: true,
        istoday: true,
        done: function (value, date, endDate) {
            if (value != "") {
                end.config.min = {
                    year: date.year,
                    month: date.month - 1,
                    date: date.date,
                }
            } else { //清空以后最小值
                end.config.min = {
                    year: 1970,
                    month: 1,
                    date: 1,
                }
            }
        }
    });

    
 
    form.on('submit(saveBtn)', function (data) {
        //  var str = encodeURIComponent(ue.getContent()); //获取富文本 内容
        //  text = decodeURIComponent(str); //将编码的内容解码
        text= ue.getContent();
        title = $("#addDy_title").val();
        source = $("#addDy_source").val();
        sendTime = $("#addDy_sendTime").val();
        shared.ajaxPost('/admin/dynamicNews/addDynamicNews', {
                title: title,
                source: source,
                sendTime: sendTime,
                text: text
            },
            function (res) {
                $('#submit').attr('disabled', true); 
               
            },{async : false}) 
                layer.closeAll();
                parent.dyRefreshTable();             
        return false;
    });

        /** 设置关闭按钮的click事件处理 */
    function closeAddDynamic() {
        layer.confirm('确定丢弃新建页面内容？', function (index) {
            layer.closeAll();
        });
    }

    function getImage(thisImg,path, parameter) {              
        thisImg.src = config.server + "/" + path + "/" + parameter;
        thisImg.onerror = null;
    }

    function getFile(path){
        var url = config.server + "/" + path + "/" + parameter;
        window.location.href = url;
     }


    
</script>